from .base import db
from datetime import datetime

class RewardPunishment(db.Model):
    __tablename__ = 'reward_punishment'
    id = db.Column(db.Integer, primary_key=True)
    employee_id = db.Column(db.Integer, db.ForeignKey('employee.id'), nullable=False)
    type = db.Column(db.String(20), nullable=False)  # 奖惩类型
    reason = db.Column(db.Text, nullable=False)      # 奖惩原因
    date = db.Column(db.String(20), nullable=False)  # 奖惩时间
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def to_dict(self):
        return {
            'id': self.id,
            'employee_id': self.employee_id,
            'type': self.type,
            'reason': self.reason,
            'date': self.date,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
            'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None
        } 